package com.zrwl.poscloud.commons.utils;

public class ASCIIUtils {
    /**
     * 字符串转换为ASCII
     *
     * @param value
     * @return
     */
    public static String ConvertToASCII(String value) {
        StringBuffer sbu = new StringBuffer();
        char[] ch = value.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if (i != ch.length - 1) {
                sbu.append((int) ch[i]).append(",");
            } else {
                sbu.append((int) ch[i]);
            }
        }
        return sbu.toString();
    }

    /**
     * ASCII转换为字符串
     * @param value
     * @return
     */
    public static String ASCIIToConvert(String value) {
        StringBuffer sbu = new StringBuffer();
        String[] chars = value.split(",");
        for (int i = 0; i < chars.length; i++) {
            // 重点 先将String转成int，再强转成char，最后添加到StringBuffer中
            sbu.append((char) Integer.parseInt(chars[i]));
        }
        return sbu.toString();
    }

}